package com.infra.micro.oss.controller;

import com.infra.micro.oss.domain.service.PreviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RequestMapping("/api/oss/file/preview")
@RestController
@Api(tags = {"文件预览服务"})
public class PreviewController {
    @Resource
    private PreviewService previewService;

    @ApiImplicitParam(name = "fileId", value = "系统文件ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true)
    @ApiOperation(value = "根据系统文件ID预览文件", notes = "根据系统文件ID预览文件", produces = "application/json")
    @GetMapping("/fileInfo/{fileId}")
    public void previewByFileId(@PathVariable("fileId") Long fileId, HttpServletResponse response) throws Exception {
        previewService.previewByFileId(fileId, response);
    }

    @ApiImplicitParam(name = "bizId", value = "业务文件ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true)
    @ApiOperation(value = "根据业务文件ID预览文件", notes = "根据业务文件ID预览文件", produces = "application/json")
    @GetMapping("/bizInfo/{bizId}")
    public void previewByBizId(@PathVariable("bizId") Long bizId, HttpServletResponse response) throws Exception {
        previewService.previewByBizId(bizId, response);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "fileId", value = "系统文件ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true),
            @ApiImplicitParam(name = "thumbnail", value = "缩略图尺寸(格式:w*h,样例:100*100)", dataType = "String", dataTypeClass = String.class, paramType = "path", required = true)
    })
    @ApiOperation(value = "根据系统文件ID预览缩略图", notes = "根据系统文件ID预览缩略图", produces = "application/json")
    @GetMapping("/fileInfo/{fileId}/{thumbnail}")
    public void previewThumbnailByFileId(@PathVariable("fileId") Long fileId, @PathVariable("thumbnail") String thumbnail, HttpServletResponse response) throws Exception {
        previewService.previewThumbnailByFileId(fileId, thumbnail, response);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "bizId", value = "业务文件ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true),
            @ApiImplicitParam(name = "thumbnail", value = "缩略图尺寸(格式:w*h,样例:100*100)", dataType = "String", dataTypeClass = String.class, paramType = "path", required = true)
    })
    @ApiOperation(value = "根据业务文件ID预览缩略图", notes = "根据业务文件ID预览缩略图", produces = "application/json")
    @GetMapping("/bizInfo/{bizId}/{thumbnail}")
    public void previewThumbnailByBizId(@PathVariable("bizId") Long bizId, @PathVariable("thumbnail") String thumbnail, HttpServletResponse response) throws Exception {
        previewService.previewThumbnailByBizId(bizId, thumbnail, response);
    }
}
